/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DesenvolvedorView.java
 *
 * Created on 28/10/2011, 04:31:06
 */
package br.com.geftu.view;

import br.com.geftu.HibernateUtil.HibernateUtil;
import br.com.geftu.dao.DAO;
import br.com.geftu.model.Desenvolvedor;
import br.com.geftu.model.Participa;
import br.com.geftu.util.MaskF;
import br.com.geftu.util.ValidaCPF;
import java.awt.HeadlessException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.hibernate.Session;
import javax.swing.JFormattedTextField;

/**
 *
 * @author jorgenei
 */
public final class DesenvolvedorView extends javax.swing.JFrame {
List<Desenvolvedor> lista_desenvolvedor = new ArrayList();
List<Participa> lista_participa = new ArrayList();
Integer posicao_atual = 0;
String ordem = "order by iddes";
String listar = "from Desenvolvedor ";

    /** Creates new form DesenvolvedorView */
    public DesenvolvedorView() {
        initComponents();
        preencherDesenvolvedor();
    }
       

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupordenar = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        tf_pesquisa = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        rb_nome = new javax.swing.JRadioButton();
        rb_codigo = new javax.swing.JRadioButton();
        jButton5 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        tf_login = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tf_nome = new javax.swing.JTextField();
        tf_codigo = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tf_senha = new javax.swing.JTextField();
        tf_cpf = tf_cpf = new JFormattedTextField(MaskF.mascara("cpf"));
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cadastro Desenvolvedores");

        jPanel1.setName("jPanel1"); // NOI18N

        tf_pesquisa.setName("tf_pesquisa"); // NOI18N
        tf_pesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_pesquisaKeyPressed(evt);
            }
        });

        jLabel7.setText("Pesquisa:");
        jLabel7.setName("jLabel7"); // NOI18N

        jButton1.setText("Novo");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Salvar");
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Excluir");
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPanel4.setBackground(new java.awt.Color(204, 255, 153));
        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setName("jPanel4"); // NOI18N

        jLabel8.setText("Ordenar:");
        jLabel8.setName("jLabel8"); // NOI18N

        rb_nome.setBackground(new java.awt.Color(204, 255, 153));
        groupordenar.add(rb_nome);
        rb_nome.setText("Nome");
        rb_nome.setName("rb_nome"); // NOI18N
        rb_nome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_nomeActionPerformed(evt);
            }
        });

        rb_codigo.setBackground(new java.awt.Color(204, 255, 153));
        groupordenar.add(rb_codigo);
        rb_codigo.setSelected(true);
        rb_codigo.setText("Código");
        rb_codigo.setName("rb_codigo"); // NOI18N
        rb_codigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_codigoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rb_nome)
                    .addComponent(rb_codigo))
                .addContainerGap(9, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rb_codigo)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rb_nome)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton5.setText("Fechar");
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(tf_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton5)
                .addGap(32, 32, 32)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(160, 160, 160))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(tf_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton2)
                            .addComponent(jButton3)
                            .addComponent(jButton5)))
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setName("jPanel3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Código", "Nome", "CPF", "login"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel4.setText("CPF:");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel1.setText("Código:");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setText("Nome:");
        jLabel3.setName("jLabel3"); // NOI18N

        tf_login.setName("tf_login"); // NOI18N

        jLabel6.setText("Senha:");
        jLabel6.setName("jLabel6"); // NOI18N

        tf_nome.setName("tf_nome"); // NOI18N

        tf_codigo.setName("tf_codigo"); // NOI18N

        jLabel5.setText("Login:");
        jLabel5.setName("jLabel5"); // NOI18N

        tf_senha.setName("tf_senha"); // NOI18N
        tf_senha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_senhaActionPerformed(evt);
            }
        });

        tf_cpf.setName("tf_cpf"); // NOI18N
        tf_cpf.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tf_cpfFocusLost(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(tf_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_login, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_senha)))
                .addGap(55, 55, 55))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(tf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(tf_login, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(tf_senha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Lista de desenvolvedores");
        jLabel2.setName("jLabel2"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addGap(5, 5, 5)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 555, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-602)/2, (screenSize.height-471)/2, 602, 471);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        try
        {
         Desenvolvedor desenvolvedor = new Desenvolvedor();
         if(tf_codigo.getText().equals(""))
         {             
             desenvolvedor.setNome(tf_nome.getText().toString());
             desenvolvedor.setCpf(tf_cpf.getText().toString());
             desenvolvedor.setLogin(tf_login.getText().toString());
             desenvolvedor.setSenha(tf_senha.getText().toString());
             DAO objdesenvolvedor = new DAO(desenvolvedor);
             objdesenvolvedor.insere();
         }
         else
         {             
             String alterar = "Tem certeza de que deseja alterar o registro?";
             int opcao_escolhida = JOptionPane.showConfirmDialog(null, alterar,"Exclusão ",JOptionPane.YES_OPTION);
             if (opcao_escolhida == JOptionPane.YES_OPTION)
             {
                 desenvolvedor.setIddes(Integer.parseInt(tf_codigo.getText()));
                 desenvolvedor.setNome(tf_nome.getText().toString());
                 desenvolvedor.setCpf(tf_cpf.getText().toString());              
                 desenvolvedor.setLogin(tf_login.getText().toString());
                 desenvolvedor.setSenha(tf_senha.getText().toString());
                 DAO objdesenvolvedor = new DAO(desenvolvedor);
                 objdesenvolvedor.insere();
             }
             
         }
         preencherDesenvolvedor();

        }
        catch(HeadlessException | NumberFormatException erro)
        {
             JOptionPane.showMessageDialog(null,"Erro na insersão : "+erro);
        }// TODO add your handling code here:        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void tf_senhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_senhaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_senhaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       tf_codigo.setText("");
       tf_nome.setText("");
       tf_cpf.setText("");
       tf_login.setText("");
       tf_senha.setText("");
       tf_nome.requestFocus();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void rb_nomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_nomeActionPerformed
       ordem = "order by nome";       
       preencherDesenvolvedor();
    }//GEN-LAST:event_rb_nomeActionPerformed

    private void rb_codigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_codigoActionPerformed
       
       ordem = "order by iddes";
       preencherDesenvolvedor();
    }//GEN-LAST:event_rb_codigoActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
            int linha = jTable1.getSelectedRow();
            tf_codigo.setText(jTable1.getValueAt(linha, 0).toString());
            tf_nome.setText(jTable1.getValueAt(linha, 1).toString());         
            tf_cpf.setText(jTable1.getValueAt(linha, 2).toString());
            tf_login.setText(jTable1.getValueAt(linha, 3).toString());
                      
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        String excluir = "Tem certeza de que deseja excluir o registro "+tf_nome.getText()+"?";
        
        int opcao_escolhida = JOptionPane.showConfirmDialog(null, excluir,"Exclusão ",JOptionPane.YES_OPTION);
        if (opcao_escolhida == JOptionPane.YES_OPTION)
        {
            try
            {
             Desenvolvedor desenvolvedor = new Desenvolvedor();            
             desenvolvedor.setIddes(Integer.parseInt(tf_codigo.getText()));
             DAO obdesenv = new DAO(desenvolvedor);
             obdesenv.excluir();
             preencherDesenvolvedor();
            }
            catch(NumberFormatException | HeadlessException erro)
            {
                 JOptionPane.showMessageDialog(null,"Erro na insersão : "+erro);
            }
        } else
            JOptionPane.showMessageDialog(null,"Registro não excluído.");
    }
        // TODO add your handling code here:        // TODO add your handling code here:}//GEN-LAST:event_jButton3ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        encerrar();         // TODO add your handling code here:}//GEN-LAST:event_jButton5ActionPerformed
    }
        private void tf_pesquisaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_pesquisaKeyPressed
        listar = "from Desenvolvedor where upper(nome) like '%"+tf_pesquisa.getText().toUpperCase()+"%'";
        preencherDesenvolvedor();        // TODO add your handling code here:
    }//GEN-LAST:event_tf_pesquisaKeyPressed

    private void tf_cpfFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tf_cpfFocusLost
        Boolean situac = ValidaCPF.validaCPF(tf_cpf.getText().toString());         
        if(!situac){
            String aviso = "O CPF informado é inválido, deseja corrigir?";
             int opcao_escolhida = JOptionPane.showConfirmDialog(null, aviso,"Exclusão ",JOptionPane.YES_OPTION);
             if (opcao_escolhida == JOptionPane.YES_OPTION){
                 tf_cpf.requestFocus();
             }
        }
        
    }//GEN-LAST:event_tf_cpfFocusLost

    /**
     * @param args the command line arguments
     */
        //xx1
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new DesenvolvedorView().setVisible(true);
            }
        });
    }//xx1
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup groupordenar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JRadioButton rb_codigo;
    private javax.swing.JRadioButton rb_nome;
    private javax.swing.JTextField tf_codigo;
    private javax.swing.JFormattedTextField tf_cpf;
    private javax.swing.JTextField tf_login;
    private javax.swing.JTextField tf_nome;
    private javax.swing.JTextField tf_pesquisa;
    private javax.swing.JTextField tf_senha;
    // End of variables declaration//GEN-END:variables

    
public void preencherDesenvolvedor()
    { 
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(10);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(70);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(40);
             
        DefaultTableModel modelo = (DefaultTableModel)jTable1.getModel();
        modelo.setNumRows(0);
        
               
        
       try
        {
            Session sessao = HibernateUtil.getSession();

            lista_desenvolvedor = sessao.createQuery(listar+ordem).list();

            int tamanho_lista = lista_desenvolvedor.size();      
            
                for(int i=0;i< tamanho_lista;i++)
                {
                    Desenvolvedor desenvolvedor = lista_desenvolvedor.get(i);
                    modelo.addRow(new Object [] {desenvolvedor.getIddes(),desenvolvedor.getNome(),desenvolvedor.getCpf(),desenvolvedor.getLogin()});                    
                }
            if(! lista_desenvolvedor.isEmpty())
              {
                Desenvolvedor desenvolvedor = lista_desenvolvedor.get(0);
                tf_codigo.setText(""+desenvolvedor.getIddes());
                tf_nome.setText(desenvolvedor.getNome());
                tf_cpf.setText(desenvolvedor.getCpf());
                tf_login.setText(desenvolvedor.getLogin());
                tf_codigo.disable();
                lista_desenvolvedor = sessao.createQuery(listar+ordem).list();
                //bt_verifica.setVisible(false);                
            }
        
         }
        catch(Exception erro)
        {
             JOptionPane.showMessageDialog(null,"Erro na insersão : "+erro);
        }
    }

   

public void encerrar(){
    setVisible(false);
    RelatoView.getInstance().setVisible(true);
}
}
